package com.example.njupt.base;

import android.app.Application;

import com.alibaba.android.arouter.launcher.ARouter;

import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterEngineCache;
import io.flutter.embedding.engine.dart.DartExecutor;

/**
 * Author:      mwang
 * Create Date: Created in 2021/4/25 9:28
 * Update Date:
 * Modified By:
 * Description:
 */
public class BaseApplication extends Application {
    private boolean isARoute = true;
    private FlutterEngine flutterEngine;

    private static Application application;


    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        if (isARoute) {
            ARouter.openLog();
            ARouter.openDebug();
        }
        ARouter.init(BaseApplication.this);

        flutterEngine = new FlutterEngine(this);

        flutterEngine.getDartExecutor().executeDartEntrypoint(DartExecutor.DartEntrypoint.createDefault());

        FlutterEngineCache.getInstance().put("njupt_flutter_engine", flutterEngine);
    }

    public static Application getInstance() {
        return application;
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        ARouter.getInstance().destroy();
    }
}
